namespace ne   {

    export enum ELOGLEVEL {
        CRITICAL = 50,
        ERROR = 40,
        WARNING = 30,
        INFO = 20,
        DEBUG = 10,
        NOTSET = 0
    }

    export class Logger {

        private _tag: string;                               //Logger tag
        private _handlers: any[];                           //handler list
        private _loglevel: ELOGLEVEL;                       //log level

        /**
         * Creates an instance of Logger.
         * @param {string} stag 
         * @memberof Logger
         */
        public constructor(stag: string) {
            this._tag = stag; 
            this._handlers = [];
            this._loglevel = ELOGLEVEL.DEBUG 
        }

        /**
         * 添加handler队形用于输出
         * @param  objhandler 
         * @memberof Logger
         */
        public addHandler(objhandler: any):void {
            this._handlers.push(objhandler);
        }

        /**
         * 设置Logger的输出level等级
         * 
         * @param {LOGLEVEL} lv 
         * @memberof Logger
         */
        public setLogLevel(nlv: ELOGLEVEL):void {
            this._loglevel = nlv;
        }

        /**
         * notset等级的输出
         * 
         * @param {string} sout 
         * @memberof Logger
         */
        public notset(sfmt: string, ...sout):void {
            this.log(ELOGLEVEL.NOTSET, sfmt,...sout);
        }

        /**
         * info等级的输出
         * 
         * @param {string} sout 
         * @memberof Logger
         */
        public info(sfmt: string, ...sout:any[]):void {
            this.log(ELOGLEVEL.INFO, sfmt,...sout);
        }

        /**
         * debug等级的输出
         * 
         * @param {string} sout 
         * @memberof Logger
         */
        public debug(sfmt: string, ...sout):void {
            this.log(ELOGLEVEL.DEBUG, sfmt,...sout);
        }

        /**
         * acritical等级的输出
         * 
         * @param {string} sout 
         * @memberof Logger
         */
        public critical(sfmt: string, ...sout):void {
            this.log(ELOGLEVEL.CRITICAL, sfmt,...sout);
        }

        /**
         * error等级的输出
         * 
         * @param {string} sout 
         * @memberof Logger
         */
        public error(sfmt: string, ...sout):void {
            this.log(ELOGLEVEL.ERROR, sfmt,...sout);
        }

        /**
         * warning等级的输出 
         * 
         * @param {string} sout 
         * @memberof Logger
         */
        public warning(sfmt: string, ...sout):void {
            this.log(ELOGLEVEL.WARNING, sfmt,...sout)
        }

        
        private log(nlv: ELOGLEVEL, sfmt: string, ...sout) {
            let self = this;
            this._handlers.forEach(objandler => {
                if (self._loglevel <= nlv) {
                    objandler.emit(nlv, sfmt,...sout);
                }
            });
        }

    }
}